/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package TestCase.Dup;

import classgenerator.logic.Oracle;
import classgenerator.logic.OracleImpl;
import deadCodeRmv.StartMeDCR;
import takatuka.classreader.dataObjs.ClassFile;
import takatuka.classreader.dataObjs.MethodInfo;
import takatuka.classreader.logic.constants.JavaInstructionsOpcodes;
import takatuka.classreader.logic.factory.FactoryFacade;
import takatuka.classreader.logic.factory.FactoryPlaceholder;

/**
 *
 * @author irfan
 */
public class Dup2_x2TestCase extends StartMeDCR {

    public static void main(String args[]) throws Exception {
        new Dup2_x2TestCase().start(args);
    }

    @Override
    public void execute(String args[]) throws Exception {
        Oracle oracle = new OracleImpl();
        FactoryFacade factoryFacade = FactoryPlaceholder.getInstanceOf().getFactory();
        ClassFile cFile = oracle.createEmptyClassFile("Dup2_x2TestCase", "Dup2_x2TestCase.java");



        MethodInfo constrMethodInfo = oracle.addDefaultConstructor(cFile);
//
//
        int defaultConstrRefInfo = oracle.addMethodRefInCP(cFile, cFile.getThisClass().intValueSigned(),
                oracle.getUTF8FromCP(cFile, constrMethodInfo.getNameIndex().intValueSigned()),
                oracle.getUTF8FromCP(cFile, constrMethodInfo.getDescriptorIndex().intValueSigned()));


        /**
         * added the main method in the class file without any code
         */
        MethodInfo mainMethod = oracle.addMainFunction(cFile);

        /**
         * bipush 100
         */
        oracle.addInstruction(cFile, mainMethod, factoryFacade.createInstruction(JavaInstructionsOpcodes.BIPUSH, factoryFacade.createUn(100).trim(1), mainMethod.getCodeAtt()));


        /**
         * bipush 99
         */
        oracle.addInstruction(cFile, mainMethod, factoryFacade.createInstruction(JavaInstructionsOpcodes.BIPUSH, factoryFacade.createUn(99).trim(1), mainMethod.getCodeAtt()));

        /**
         * bipush 98
         */
        oracle.addInstruction(cFile, mainMethod, factoryFacade.createInstruction(JavaInstructionsOpcodes.BIPUSH, factoryFacade.createUn(98).trim(1), mainMethod.getCodeAtt()));

        /**
         * bipush 97
         */
        oracle.addInstruction(cFile, mainMethod, factoryFacade.createInstruction(JavaInstructionsOpcodes.BIPUSH, factoryFacade.createUn(97).trim(1), mainMethod.getCodeAtt()));



        /**
         * dup2_x2
         */
        oracle.addInstruction(cFile, mainMethod, factoryFacade.createInstruction(JavaInstructionsOpcodes.DUP2_X2, mainMethod.getCodeAtt()));





        /**
         * ISTORE_0
         *
         */
        oracle.addInstruction(cFile, mainMethod, factoryFacade.createInstruction(JavaInstructionsOpcodes.ISTORE_0, mainMethod.getCodeAtt()));
        /**
         * ISTORE_1
         *
         */
        oracle.addInstruction(cFile, mainMethod, factoryFacade.createInstruction(JavaInstructionsOpcodes.ISTORE_1, mainMethod.getCodeAtt()));
        /**
         * ISTORE_2
         *
         */
        oracle.addInstruction(cFile, mainMethod, factoryFacade.createInstruction(JavaInstructionsOpcodes.ISTORE_2, mainMethod.getCodeAtt()));

        /**
         * ISTORE_3
         *
         */
        oracle.addInstruction(cFile, mainMethod, factoryFacade.createInstruction(JavaInstructionsOpcodes.ISTORE_3, mainMethod.getCodeAtt()));
        /**
         * ISTORE_4
         *
         */
        oracle.addInstruction(cFile, mainMethod, factoryFacade.createInstruction(JavaInstructionsOpcodes.ISTORE, factoryFacade.createUn(4).trim(1), mainMethod.getCodeAtt()));
        /**
         * ISTORE_4
         *
         */
        oracle.addInstruction(cFile, mainMethod, factoryFacade.createInstruction(JavaInstructionsOpcodes.ISTORE, factoryFacade.createUn(5).trim(1), mainMethod.getCodeAtt()));

        /*
         * 
         * printing integer result
         */
        oracle.print(cFile, mainMethod, "Result Should be in sequence of : \n97\n98\n99\n100\n98\n97\n98\nResult is:");
        oracle.print(cFile, mainMethod, 0, true);
        oracle.print(cFile, mainMethod, 1, true);
        oracle.print(cFile, mainMethod, 2, true);
        oracle.print(cFile, mainMethod, 3, true);

        oracle.print(cFile, mainMethod, 4, true);
        oracle.print(cFile, mainMethod, 5, true);



        /**
         * return
         */
        oracle.addInstruction(cFile, mainMethod, factoryFacade.createInstruction(JavaInstructionsOpcodes.RETURN, mainMethod.getCodeAtt()));
        super.execute(args);
    }
}
